package per.turtle.common.core.web.page;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

/**
 * 分页数据
 *
 * @author turtle
 */
@Data
public class PageDomain {

    private static final String ASC = "asc";

    private static final String DESC = "desc";

    /**
     * 当前记录起始索引
     */
    private Integer pageNum;

    /**
     * 每页显示记录数
     */
    private Integer pageSize;

    /**
     * 排序列
     */
    private String orderColumn;

    /**
     * 排序的方向desc或者asc
     */
    private String orderType = "asc";

    public String getOrderBy() {
        if (StrUtil.isBlank(orderColumn)) {
            return "";
        }
        return StrUtil.toUnderlineCase(orderColumn) + " " + orderType;
    }

    public void setIsAsc(String isAsc) {
        if (StrUtil.isNotEmpty(isAsc)) {
            // 兼容前端排序类型
            if (!ASC.equalsIgnoreCase(isAsc)) {
                this.orderType = DESC;
            }
        }
    }

}
